var searchparam;
/**
 *model 
 */    
    Ext.define('model_jyz', {
         extend: 'Ext.data.Model',
         fields: [
                {name: 'jyz_bh', type: 'string'},
                {name: 'jyz_mc', type: 'string'},
                {name: 'jyz_sh', type: 'string'},
                {name: 'jyz_swjg', type: 'string'},
                {name: 'jyz_swjg_mc', type: 'string'},
                {name: 'jyz_xzqh', type: 'string'},
                {name: 'jyz_xzqh_mc', type: 'string'},
                {name: 'jyz_dz', type: 'string'},
                {name: 'jyz_lxr', type: 'string'},
                {name: 'jyz_dh', type: 'string'},
                {name: 'jyz_bz', type: 'string'},
                {name: 'jyz_swjg_mc', type: 'string'}
         ]
     });
/**
 *store 
 */     
     var store_jyz=Ext.create('Ext.data.Store', {
        model: 'model_jyz',
        autoDestroy: true,
        autoLoad: false,
        pageSize:100,
        listeners:{
            beforeload:function(store,operation,eOpts){//添加事件在获取数据前触发
                if(searchparam){
                    store.proxy.extraParams=searchparam;
                }
            }
        },
        proxy: {
            type: 'ajax',
            url: 'getGasListAction.action',
            reader: {
                type: 'json',
                root: 'items',
                totalProperty:'totalCount'
            }
        }
     });

 /**
  *grid表格头 
  */    
     var col_jyz=[
        {xtype:'rownumberer'}, 
        {dataIndex:'jyz_swjg',text:'税务机关代码',width:120,menuDisabled:true,sortable:false},
        {dataIndex:'jyz_swjg_mc',text:'税务机关名称',width:150,menuDisabled:true,sortable:false},
        {dataIndex:'jyz_bh',text:'加油站编号',width:100,menuDisabled:true,sortable:false},
        {dataIndex:'jyz_mc',text:'加油站名称',width:120,menuDisabled:true,sortable:false},
        {dataIndex:'jyz_dz',text:'加油站地址',width:100,menuDisabled:true,sortable:false},
        {dataIndex:'jyz_lxr',text:'法人代表',width:80,menuDisabled:true,sortable:false},
        {dataIndex:'jyz_xzqh',text:'地区代码',width:80,menuDisabled:true,sortable:false},
        {dataIndex:'jyz_xzqh_mc',text:'地区名称',width:80,menuDisabled:true,sortable:false},
        {dataIndex:'jyz_sh',text:'纳税人识别号',width:150,menuDisabled:true,sortable:false},
        {dataIndex:'jyz_dh',text:'电话',width:120,menuDisabled:true,sortable:false},
        {dataIndex:'jyz_bz',text:'是否中心站',width:80,menuDisabled:true,sortable:false}
     ];

     Ext.onReady(function(){
         Ext.create('Ext.panel.Panel',{
             id:'main-panel',
             width:Ext.getBody().getWidth()-20,
             renderTo:Ext.getBody(),
             layout:{
                 type:'vbox',
                 align: 'stretch'
             },
             items:[{
                        xtype: 'grid',
                        id:'grid_jyz',
                        title:'加油站基本信息',
                        height:650,
                        //selModel: Ext.create('Ext.selection.CheckboxModel', { mode: "SIMPLE" }),
                        columns: col_jyz,            
                        store: store_jyz,
/*                        features: [{
                            groupHeaderTpl: '{name}',
                            ftype: 'summary'
                        }],*/
                       listeners: {
                           itemdblclick:function( m, record, item, index, e, eOpts ){
                               showModifDlg(record.raw);
                           }
                        },
                        dockedItems:[
                            {
                                xtype: 'toolbar',
                                items:[{
                                    xtype:'button',
                                    text:'查询',
                                    margin:'10 10 0 10',
                                    width:100,
                                    handler:showSearchDlg
                                },{
                                    xtype:'button',
                                    text:'新增',
                                    margin:'10 10 0 10',
                                    width:100,
                                    handler:showNewDlg
                                }/*
                                ,{
                                                                    xtype:'button',
                                                                    text:'淇敼',
                                                                    margin:'10 10 0 10',
                                                                    width:100,
                                                                    handler:function(){
                                                                        var g=Ext.getCmp('grid_jyz');
                                                                        var m=g.getSelectionModel().getSelection();
                                                                        if (m.length>0) {
                                                                            showModifDlg(m[0].raw);
                                                                        }else{
                                                                            Ext.Msg.alert('鎻愮ず淇℃伅','璇烽�涓淇敼鐨勫姞娌圭珯锛�);
                                                                        };
                                                                    }
                                                                },{
                                                                    xtype:'button',
                                                                    text:'鍒犻櫎',
                                                                    margin:'10 10 0 10',
                                                                    width:100,
                                                                    handler:function(){
                                                                        var g=Ext.getCmp('grid_jyz');
                                                                        var m=g.getSelectionModel().getSelection();
                                                                        if (m.length>0) {
                                                                            showDelDlg(m[0].raw);
                                                                        }else{
                                                                            Ext.Msg.alert('鎻愮ず淇℃伅','璇烽�涓鍒犻櫎鐨勫姞娌圭珯锛�);
                                                                        };
                                                                    }
                                                                }*/
                                ]
                            },{
                                xtype: 'pagingtoolbar',
                                store: store_jyz,   
                                dock: 'bottom',
                                displayInfo: true
                            }
                        ], 
                        flex: 1  
             }]
         });
     });

     function showSearchDlg(){
         var dlg=Ext.create('Ext.window.Window',{
             title:'查询条件',
             width:350,
             height:250,
             layout:'fit',
             resize:false,
             modal:true,
             items:[
                    Ext.create('Ext.form.Panel',{
                        bodyPadding:5,
                        //width:700,
                        layout:'anchor',
                        items:[
                            {
                                xtype:'textfield',
                                fieldLabel:'加油站税号',
                                name: 'jyz_sh',
                                labelWidth:80,
                                width:300
                            },{
                                xtype:'treepicker',
                                fieldLabel:'税务机关',
                                name: 'jyz_swjg',
                                valueField : 'id',
                                displayField : 'text',
                                editable:false,
                                allowBlank: false,
                                // url: 'getAreaListAction.action',
                                store : new Ext.data.TreeStore({
                                    root : {
                                        expanded : true
                                    },
                                    proxy : {
                                        type : 'ajax',
                                        url : 'getOrgListAction.action'
                                    },
                                    autoLoad : true
                                }),
                                labelWidth:80,
                                width:300
                            }
                     ],
                     buttons:[{
                            text:'提交',
                            handler:function(){
                                    searchparam=this.up('form').getForm().getValues();
                                    store_jyz.loadPage(1);
                                    dlg.close();
                            }
                        },{
                            text:'重置',handler:function(){this.up('form').getForm().reset();}
                        },{
                            text:'关闭',handler:function(){dlg.close();}
                    }]
                })
             ]
         });
         dlg.show();
     }
     function showNewDlg(){
         var dlg=Ext.create('Ext.window.Window',{
             title:'新增加油站',
             width:350,
             height:400,
             layout:'fit',
             resize:false,
             modal:true,
             items:[
                    Ext.create('Ext.form.Panel',{
                        bodyPadding:5,
                        //width:700,
                        layout:'anchor',
                        items:[
                            {
                                xtype:'textfield',
                                fieldLabel:'加油站编号',
                                name: 'jyz_bh',
                                allowBlank: false,
                                labelWidth:80,
                                width:300
                            },{
                                xtype:'textfield',
                                fieldLabel:'加油站名称',
                                name: 'jyz_mc',
                                allowBlank: false,
                                labelWidth:80,
                                width:300
                            },{
                                xtype:'textfield',
                                fieldLabel:'加油站税号',
                                name: 'jyz_sh',
                                allowBlank: false,
                                labelWidth:80,
                                width:300
                            },{
                                xtype:'treepicker',
                                fieldLabel:'税务机关',
                                name: 'jyz_swjg',
                                valueField : 'id',
                                displayField : 'text',
                                 store : new Ext.data.TreeStore({
                                    root : {
                                        expanded : true
                                    },
                                    proxy : {
                                        type : 'ajax',
                                        url : 'getOrgListAction.action'
                                    },
                                    autoLoad : true
                                }),
                                allowBlank: false,
                                labelWidth:80,
                                width:300
                            },{
                                xtype:'treepicker',
                                fieldLabel:'行政区划',
                                name: 'jyz_xzqh',
                                valueField:'id',
                                displayField : 'text',
                                store : new Ext.data.TreeStore({
                                    root : {
                                        expanded : true
                                    },
                                    proxy : {
                                        type : 'ajax',
                                        url : 'getAreaListAction.action'
                                    },
                                    autoLoad : true
                                }),
                                allowBlank: false,
                                labelWidth:80,
                                width:300
                            },{
                                xtype:'textfield',
                                fieldLabel:'加油站地址',
                                name: 'jyz_dz',
                                allowBlank: false,
                                labelWidth:80,
                                width:300
                            },{
                                xtype:'textfield',
                                fieldLabel:'加油站法人',
                                name: 'jyz_lxr',
                                allowBlank: false,
                                labelWidth:80,
                                width:300
                            },{
                                xtype:'textfield',
                                fieldLabel:'加油站电话',
                                name: 'jyz_dh',
                                allowBlank: false,
                                labelWidth:80,
                                width:300
                            },{
                                xtype:'combo',
                                fieldLabel: '加油站标志',
                                labelWidth:80,
                                width:300,
                                name: 'jyz_bz',
                                mode:'local',
                                editable:false,
                                allowBlank: false,
                                displayField:'text',
                                valueField:'id',
                                store: Ext.create('Ext.data.Store', {
                                            fields : ['id', 'text'],
                                            data:[{'id':'Y','text':'中心站'},{'id':'N','text':'普通站'}]
                                })
                            }
                     ],
                     buttons:[{
                            text:'提交',
                            handler:function(){
                                    var f=this.up('form').getForm();
                                    if (f.isValid()) {
                                        f.submit({
                                            url:'addGasAction.action',
                                            clientValidation:false,
                                            waitMsg:'正在提交数据,请稍候...',
                                            success: function(form, action){
                                                Ext.Msg.alert('提示信息',action.result.msg); 
                                                store_jyz.loadPage(1);
                                                dlg.close();
                                            },
                                            failure: function(form, action) {
                                                Ext.Msg.alert('提示信息',action.result.msg); 
                                            }
                                        });
                                    };
                            }
                        },{
                            text:'重置',handler:function(){this.up('form').getForm().reset();}
                        },{
                            text:'关闭',handler:function(){dlg.close();}
                    }]
                })
             ]
         });
         dlg.show();
     }
     function showModifDlg(raw){
         var dlg=Ext.create('Ext.window.Window',{
             title:'修改加油站',
             width:350,
             height:400,
             layout:'fit',
             resize:false,
             modal:true,
             items:[
                    Ext.create('Ext.form.Panel',{
                        bodyPadding:5,
                        //width:700,
                        layout:'anchor',
                        items:[
                            {
                                xtype:'textfield',
                                fieldLabel:'加油站编号',
                                name: 'jyz_bh',
                                value:raw.jyz_bh,
                                readOnly:true,
                                allowBlank: false,
                                labelWidth:80,
                                width:300
                            },{
                                xtype:'textfield',
                                fieldLabel:'加油站名称',
                                name: 'jyz_mc',
                                value:raw.jyz_mc,
                                allowBlank: false,
                                labelWidth:80,
                                width:300
                            },{
                                xtype:'textfield',
                                fieldLabel:'加油站税号',
                                name: 'jyz_sh',
                                value:raw.jyz_sh,
                                allowBlank: false,
                                labelWidth:80,
                                width:300
                            },{
                                xtype:'treepicker',
                                fieldLabel:'税务机关',
                                name: 'jyz_swjg',
                                value:raw.jyz_swjg,
                                valueField:'id',
                                displayField : 'text',
                                store : new Ext.data.TreeStore({
                                    root : {
                                        expanded : true
                                    },
                                    proxy : {
                                        type : 'ajax',
                                        url : 'getOrgListAction.action'
                                    },
                                    autoLoad : true
                                }),
                                allowBlank: false,
                                labelWidth:80,
                                width:300
                            },{
                                xtype:'treepicker',
                                fieldLabel:'行政区划',
                                name: 'jyz_xzqh',
                                value:raw.jyz_xzqh,
                                valueField:'id',
                                displayField : 'text',
                                store : new Ext.data.TreeStore({
                                    root : {
                                        expanded : true
                                    },
                                    proxy : {
                                        type : 'ajax',
                                        url : 'getAreaListAction.action'
                                    },
                                    autoLoad : true
                                }),
                                allowBlank: false,
                                labelWidth:80,
                                width:300
                            },{
                                xtype:'textfield',
                                fieldLabel:'加油站地址',
                                name: 'jyz_dz',
                                value:raw.jyz_dz,
                                allowBlank: false,
                                labelWidth:80,
                                width:300
                            },{
                                xtype:'textfield',
                                fieldLabel:'加油站法人',
                                name: 'jyz_lxr',
                                value:raw.jyz_lxr,
                                allowBlank: false,
                                labelWidth:80,
                                width:300
                            },{
                                xtype:'textfield',
                                fieldLabel:'加油站电话',
                                name: 'jyz_dh',
                                value:raw.jyz_dh,
                                allowBlank: false,
                                labelWidth:80,
                                width:300
                            },{
                                xtype:'combo',
                                fieldLabel: '加油站标志',
                                labelWidth:80,
                                width:300,
                                name: 'jyz_bz',
                                value:raw.jyz_bz,
                                mode:'local',
                                editable:false,
                                allowBlank: false,
                                displayField:'text',
                                valueField:'id',
                                store: Ext.create('Ext.data.Store', {
                                            fields : ['id', 'text'],
                                            data:[{'id':'Y','text':'中心站'},{'id':'N','text':'普通站'}]
                                })
                            }
                     ],
                     buttons:[{
                            text:'修改',
                            handler:function(){
                                    var f=this.up('form').getForm();
                                    Ext.Msg.show({
                                        title:'修改',
                                        msg:'是否要修改加油站信息？',
                                        width:300,
                                        buttons:Ext.Msg.OKCANCEL,
                                        icon: Ext.MessageBox.INFO,
                                        fn:function(buttonId,text,opt){
                                            if(buttonId=='ok'){
                                               
                                                if (f.isValid()) {
                                                    f.submit({
                                                        url:'modifGasAction.action',
                                                        clientValidation:false,
                                                        waitMsg:'正在提交数据,请稍候...',
                                                        success: function(form, action){
                                                            Ext.Msg.alert('提示信息',action.result.msg); 
                                                            store_jyz.loadPage(1);
                                                            dlg.close();
                                                        },
                                                        failure: function(form, action) {
                                                            Ext.Msg.alert('提示信息',action.result.msg); 
                                                        }
                                                    });
                                                };
                                            }
                                        }
                                  });
                            }
                        },{
                            text:'删除',
                            handler:function(){
                                    var f=this.up('form').getForm();
                                  Ext.Msg.show({
                                        title:'删除',
                                        msg:'是否要删除加油站信息？',
                                        width:300,
                                        buttons:Ext.Msg.OKCANCEL,
                                        icon: Ext.MessageBox.INFO,
                                        fn:function(buttonId,text,opt){
                                            if(buttonId=='ok'){
                                               
                                                if (f.isValid()) {
                                                    f.submit({
                                                        url:'delGasAction.action',
                                                        clientValidation:false,
                                                        waitMsg:'正在提交数据,请稍候...',
                                                        success: function(form, action){
                                                            Ext.Msg.alert('提示信息',action.result.msg); 
                                                            store_jyz.loadPage(1);
                                                            dlg.close();
                                                        },
                                                        failure: function(form, action) {
                                                            Ext.Msg.alert('提示信息',action.result.msg); 
                                                        }
                                                    });
                                                };
                                            }
                                        }
                                  });
                            }
                        },{
                            text:'关闭',handler:function(){dlg.close();}
                    }]
                })
             ]
         });
         dlg.show();
     }
     function showDelDlg(raw){
         var dlg=Ext.create('Ext.window.Window',{
             title:'删除加油站',
             width:350,
             height:400,
             layout:'fit',
             resize:false,
             modal:true,
             items:[
                    Ext.create('Ext.form.Panel',{
                        bodyPadding:5,
                        //width:700,
                        layout:'anchor',
                        items:[
                            {
                                xtype:'textfield',
                                fieldLabel:'加油站编号',
                                name: 'jyz_bh',
                                value:raw.jyz_bh,
                                readOnly:true,
                                labelWidth:80,
                                width:300
                            },{
                                xtype:'textfield',
                                fieldLabel:'加油站名称',
                                name: 'jyz_mc',
                                value:raw.jyz_mc,
                                readOnly:true,
                                labelWidth:80,
                                width:300
                            },{
                                xtype:'textfield',
                                fieldLabel:'加油站税号',
                                name: 'jyz_sh',
                                value:raw.jyz_sh,
                                readOnly:true,
                                labelWidth:80,
                                width:300
                            },{
                                xtype:'treecombobox',
                                fieldLabel:'税务机关',
                                name: 'jyz_swjg',
                                value:raw.jyz_swjg,
                                readOnly:true,
                                valueField:'id',
                                url: 'getOrgListAction.action',
                                labelWidth:80,
                                width:300
                            },{
                                xtype:'treecombobox',
                                fieldLabel:'行政区划',
                                name: 'jyz_xzqh',
                                value:raw.jyz_xzqh,
                                readOnly:true,
                                valueField:'id',
                                url: 'getAreaListAction.action',
                                labelWidth:80,
                                width:300
                            },{
                                xtype:'textfield',
                                fieldLabel:'加油站地址',
                                name: 'jyz_dz',
                                value:raw.jyz_dz,
                                readOnly:true,
                                labelWidth:80,
                                width:300
                            },{
                                xtype:'textfield',
                                fieldLabel:'加油站法人',
                                name: 'jyz_lxr',
                                value:raw.jyz_lxr,
                                readOnly:true,
                                labelWidth:80,
                                width:300
                            },{
                                xtype:'textfield',
                                fieldLabel:'加油站电话',
                                name: 'jyz_dh',
                                value:raw.jyz_dh,
                                readOnly:true,
                                labelWidth:80,
                                width:300
                            },{
                                xtype:'combo',
                                fieldLabel: '加油站标志',
                                labelWidth:80,
                                width:300,
                                name: 'jyz_bz',
                                value:raw.jyz_bz,
                                readOnly:true,
                                mode:'local',
                                editable:false,
                                allowBlank: false,
                                displayField:'text',
                                valueField:'id',
                                store: Ext.create('Ext.data.Store', {
                                            fields : ['id', 'text'],
                                            data:[{'id':'Y','text':'中心站'},{'id':'N','text':'普通站'}]
                                })
                            }
                     ],
                     buttons:[{
                            text:'提交',
                            handler:function(){
                                    var f=this.up('form').getForm();
                                    if (f.isValid()) {
                                        f.submit({
                                            url:'delGasAction.action',
                                            clientValidation:false,
                                            waitMsg:'正在提交数据,请稍候...',
                                            success: function(form, action){
                                                Ext.Msg.alert('提示信息',action.result.msg); 
                                                store_jyz.loadPage(1);
                                                dlg.close();
                                            },
                                            failure: function(form, action) {
                                                Ext.Msg.alert('提示信息',action.result.msg); 
                                            }
                                        });
                                    };
                            }
                        },{
                            text:'重置',handler:function(){this.up('form').getForm().reset();}
                        },{
                            text:'关闭',handler:function(){dlg.close();}
                    }]
                })
             ]
         });
         dlg.show();
     }